<?php
// namespace demo;
/**
 *
 * @authors  Ysg (y.shi.guo@gmail.com)
 * @website  http://ysg.bonza.cn
 * @date     2017-07-24 11:43:02
 */

header("Content-type:text/html;charset:utf8;");
header("Pragma: no-cache");
header("Pragma: no-cache");

date_default_timezone_set('PRC');

define("ROOT_PATH",realpath('.'));

$message = 'hello';

/*// 没有 "use"
$example = function () {
    var_dump($message);
};
echo $example();*/

// 继承 $message
// $example = function () use ($message) {
//     var_dump($message);
// };
// echo $example();

// Inherited variable's value is from when the function
// is defined, not when called
// $message = 'world';
// echo $example();

// Reset message
$message = 'hello';

// Inherit by-reference
$example = function () use (&$message) {
    var_dump($message);
};
// echo $example();

// The changed value in the parent scope
// is reflected inside the function call
$message = 'world';
echo $example();

// Closures can also accept regular arguments
$example = function ($arg) use ($message) {
    var_dump($arg . ' ' . $message);
};
$example("hello");
